package middleware

import (
	"main.go/utils"

	"github.com/gin-gonic/gin"
	"main.go/model/common/response"
)

func Auth(score string) gin.HandlerFunc {
	return func(c *gin.Context) {
		tokenInfo, err := utils.GetClaims(c)
		if score != tokenInfo.Source {
			response.NoAuth("未登录或非法访问", c)
			c.Abort()
			return
		}
		if err != nil {
			response.NoAuth("未登录或非法访问", c)
			c.Abort()
			return
		}
		c.Set("claims", tokenInfo)

		c.Next()
	}
}
func IsAuth() gin.HandlerFunc {
	return func(c *gin.Context) {
		tokenInfo, err := utils.GetClaims(c)
		if err != nil {
			response.NoAuth("未登录或非法访问", c)
			c.Abort()
			return
		}
		c.Set("claims", tokenInfo)

		c.Next()
	}
}
